#include <iostream>
#include <string>
#include <cstdlib>
#include <map>

#include "hunterAPI.hpp"
#include "hunterHTTP.hpp"

using namespace std;

int main()
{
	HunterAPI::HiveMind hm("./database");
	freopen("./log", "w+", stderr);

	string cookie = getCookie();
	HunterAPI::Player tar;
	map <string, string> qry = HunterAPI::parseHTTPinput(string(getenv("QUERY_STRING")));
	int tarid = strtoint(qry["from"]); 
	if (hm.getPlayerById(tarid, tar))
	{
		cout << "Content-type: text/html;\n\n";
		o_header("Fail");
		o_internal_error("getPlayer error");
		o_footer();
		return 0;
	}
	
	int id = -1;
	if (hm.verifyCookie(cookie, id) || id == -1)
	// login failed
	{
		cout << "Content-type: text/html;\n\n";
		o_header("Fail");
		o_login_error("Session expired w/ " + cookie);
		o_footer();
		return 0;
	}
	
	HunterAPI::Player pl;
	hm.getPlayerById(id, pl);

	// change reputation
	
	string s;
	getline(cin, s);
	string q = qry["query"];
	
	cout << "Content-type: text/html;\n\n";	
	o_header("Club -- Commend Player " + inttostr(tar.id));
	o_upper_visible(pl);

//	cout << "Your input: <br> " << s << "<br>Your query, from:<br>" << q << "<br>" << tarid;
	cout << "System is not available yet.";
	
	o_footer();
	
	return 0;
}
